package com.cosin.dao.mysql;

import com.cosin.model.po.UserPO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserMapper {

    @Insert("insert into t_user(name,password,email,role)" +
            "values (#{username},#{password},#{email},#{role})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(UserPO userPO);

    @Select("select * from t_user where name=#{username}")
    @Results(id="userMap",value = {
            @Result(column = "name", property = "username"),
    })
    UserPO getUserByUsername(String username);

    /**
     * 得到所有角色信息
     */
    @Select("select * from t_user")
    @Results(id = "getAllUser", value = {
            @Result(column = "name", property = "username"),
    })
    List<UserPO> getAllUser();

    /**
     * 更改角色信息
     */
    @Update("UPDATE t_user " +
            "SET email = #{email}, " +
            "    name = #{username}, " +
            "    password = #{password}, " +
            "    role = #{role} " +
            "WHERE name = #{username}")
    int updateUser(UserPO userPO);
}
